/**
 * https://leetcode-cn.com/problems/minimum-absolute-difference-in-bst/
 * 二叉树的最小绝对差
 * @param root 
 */
const getMinimumDifference = (root: TreeNode | null): number => {
    let ans = Number.MAX_SAFE_INTEGER,
        prev = Number.MIN_SAFE_INTEGER;

    const inOrder = (n: TreeNode | null) => {
        if (n === null) return
        // 访问左子树
        inOrder(n.left);

        // 更新
        update(n.val)

        // 访问右子树
        inOrder(n.right);
    }
    // [0, 2, 5]
    const update = (val: number) => {
        const min = val - prev
        if (min < ans) {
            // 更新ans
            ans = min
        }
        // 更换prev
        prev = val
    }

    inOrder(root)
    return ans
};